from appium.webdriver.common.appiumby import AppiumBy as By

from pages.base_page import BasePage


class CollectionPage(BasePage):
    """收藏页面"""

    # === 3. 元素定位器（集中管理，便于维护） ===
    my_collection_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("收藏")')  # 主页收藏按钮
    all_recipe_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("所有菜谱")')  # 所有菜谱选项按钮
    hot_recipe_locator = (By.ID, 'com.xiachufang:id/collect_recipe_find_hot_recipe_btn')  # 【寻找高人气菜谱】按钮
    honor_locator = (By.ID, 'com.xiachufang:id/tv_title')  # 荣誉殿堂文本
    menu_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("菜单")')  # 菜单选项按钮
    course_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("课程")')  # 课程选项按钮
    div_plan_locator = (By.ID, 'com.xiachufang:id/board_title')  # 自定义计划按钮
    # 添加菜谱按钮
    add_recipe_locator = (
        By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/add_recipe").instance(0)')
    hot_course_locator = (By.ID, 'com.xiachufang:id/collect_course_find_hot_recipe_btn')  # 【寻找高人气课程】按钮
    browse_history_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("浏览历史")')  # 浏览历史选项按钮

    edit_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().description("编辑")')  # 浏览记录编辑按钮
    select_all_locator = (By.ID, 'com.xiachufang:id/tv_right')  # 全部选择按钮
    delete_locator = (By.ID, 'com.xiachufang:id/tv_delete')  # 删除按钮
    ensure_delete_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/tv_right")')  # 确认删除按钮
    # ______________
    my_course_tips_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("我的课程")')  # 我的课程文本
    add_recipe_success_tips_locator = (
        By.ANDROID_UIAUTOMATOR,
        'new UiSelector().resourceId("com.xiachufang:id/navigation_bar_title_layout")')  # "添加菜谱"文本

    # 删除全部浏览历史记录成功的提示文本
    delete_all_browse_history_success_tips_locator = (
        By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("你还未浏览过菜谱")')

    # === 4. 元素操作方法 ===

    def click_my_collection(self):
        """点击【收藏】按钮"""
        return self.click(self.my_collection_locator)

    def click_all_recipe(self):
        """点击【所有菜谱】按钮"""
        return self.click(self.all_recipe_locator)

    def click_hot_recipe(self):
        """点击【寻找高人气菜谱】按钮"""
        return self.click(self.hot_recipe_locator)

    def get_honor_text(self):
        """获取【荣誉殿堂】文本元素"""
        return self.get_text(self.honor_locator)

    def click_menu(self):
        """点击【菜单】选项按钮"""
        return self.click(self.menu_locator)

    def click_course(self):
        """点击【课程】选项按钮"""
        return self.click(self.course_locator)

    def click_div_plan(self):
        """点击【自定义计划】按钮"""
        return self.click(self.div_plan_locator)

    def click_add_recipe(self):
        """点击【添加菜谱】按钮"""
        return self.click(self.add_recipe_locator)

    def click_hot_course(self):
        """点击【寻找高人气课程】按钮"""
        return self.click(self.hot_course_locator)

    def click_browse_history(self):
        """点击【浏览历史】选项按钮"""
        return self.click(self.browse_history_locator)

    def click_edit(self):
        """点击【编辑】浏览记录按钮"""
        return self.click(self.edit_locator)

    def click_select_all(self):
        """点击【全部选择】按钮"""
        return self.click(self.select_all_locator)

    def click_delete(self):
        """点击【删除】按钮"""
        return self.click(self.delete_locator)

    def click_ensure_delete(self):
        """点击【确认删除】按钮"""
        return self.click(self.ensure_delete_locator)

    def get_my_course_tips(self):
        """获取【我的课程】提示文本"""
        return self.get_text(self.my_course_tips_locator)

    def get_add_recipe_success_tips(self):
        """获取【添加菜谱】提示文本"""
        return self.get_text(self.add_recipe_success_tips_locator, 3)

    def get_delete_all_browse_history_tips(self):
        """获取【删除全部浏览历史成功】提示文本"""
        return self.get_text(self.delete_all_browse_history_success_tips_locator)
